package com.stone.framework.task.client;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

public enum ClientFactory {

    XXX_BATCH(XxxClient.class), BUSINESS_BATCH(BusinessClient.class);

    private Class<? extends AbstractClient> clazz;

    private ClientFactory(Class<? extends AbstractClient> clazz) {
        this.clazz = clazz;
    }

    public AbstractClient getBean() {
        return Inner.getContext().getBean(this.clazz);
    }

    @Component
    private static class Inner implements ApplicationContextAware {

        private static ApplicationContext context;

        @Override
        public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
            context = applicationContext;
        }

        public static ApplicationContext getContext() {
            return context;
        }

    }

}
